package com.example.a2032.activity;

import android.os.Bundle;

import android.widget.ImageView;
import android.widget.RadioGroup;
import android.widget.TextView;

import com.example.a2032.R;
import com.example.a2032.Utils.SharedPreferenceUtils;
import com.example.a2032.Utils.Utils;
import com.example.a2032.Utils.WebSocketUtils;
import com.example.a2032.net.jstylenet.JstyleConst;
import com.example.a2032.net.jstylenet.NetSendUtils;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class CallSettingActivity extends BaseActivity {
    @BindView(R.id.iv_title)
    ImageView ivTitle;
    @BindView(R.id.tv_title)
    TextView tvTitle;
    @BindView(R.id.iv_bg_mode)
    ImageView ivBgMode;

    @BindView(R.id.radioGroup_notify)
    RadioGroup radioGroupNotify;
    @BindView(R.id.tv_timeMode)
    TextView tvTimeMode;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_phone_setting);
        ButterKnife.bind(this);
        init();
    }

    private void init() {
        String title = getIntent().getStringExtra(SettingActivity.KEY_SettingTitle);
        tvTitle.setText(title);
        radioGroupNotify.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup group, int checkedId) {
                boolean isAll = checkedId == R.id.RadioButton_all;
                SharedPreferenceUtils.setSpBoolean(SharedPreferenceUtils.KEY_TelLimit, isAll);

                changeNotifyMode(isAll);
            }
        });
        boolean isAll = SharedPreferenceUtils.getBoolean(SharedPreferenceUtils.KEY_TelLimit, true);
        radioGroupNotify.check(isAll ? R.id.RadioButton_all : R.id.RadioButton_limit);
    }

    private void changeNotifyMode(boolean isAll) {
      //  adb shell getprop persist.sys.cust_whitelist
      //  adb shell setprop persist.sys.cust_whitelist 0
      //  adb shell setprop persist.sys.answer_auto_code true
      //  adb shell getprop persist.sys.answer_auto_code
//        SystemProperties.set("persist.sys.cust_whitelist", isAll?"1":"0");
        Utils.setProperty("persist.sys.cust_whitelist", isAll?"0":"1");
        WebSocketUtils.getInstance().sendMsg(NetSendUtils.updateWhiteListState(isAll? JstyleConst.OPEN:JstyleConst.CLOSE));
        tvTimeMode.setText(isAll ? getString(R.string.notify_mode_all) : getString(R.string.notify_mode_conatct));
    }


    @OnClick(R.id.iv_title)
    public void onViewClicked() {
        finish();
    }
}